home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / Point.h < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  76 lines

  1. #ifndef    POINT_H
  2. #define    POINT_H
  3.  
  4. /*$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Point.h,v 3.0 90/05/20 00:20:47 kgorlen Rel $*/
  5.  
  6. /* Point.h -- declarations for X-Y coordinates
  7.  
  8.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  9.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  10.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  11.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  12.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  13.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  14.  
  15. Author:
  16.     K. E. Gorlen
  17.     Computer Systems Laboratory, DCRT
  18.     National Institutes of Health
  19.     Bethesda, MD 20892
  20.  
  21. $Log:    Point.h,v $
  22.  * Revision 3.0  90/05/20  00:20:47  kgorlen
  23.  * Release for 1st edition.
  24.  * 
  25. */
  26.  
  27. #include "Object.h"
  28. #include <math.h>
  29.  
  30. class Point: public VIRTUAL Object {
  31.     DECLARE_MEMBERS(Point);
  32. protected:
  33.     short xc,yc;            // x-y coordinate 
  34. protected:        // storer() functions for object I/O
  35.     virtual void storer(OIOofd&) const;
  36.     virtual void storer(OIOout&) const;
  37. public:
  38.     Point()                { xc = yc = 0; }
  39.     Point(short newx, short newy)    { xc=newx; yc=newy; }
  40.     short x() const            { return xc; }
  41.     short x(short newx)        { return xc = newx; }
  42.     short y() const            { return yc; }
  43.     short y(short newy)        { return yc = newy; }
  44.     Point operator+(const Point& p) const    { return Point(xc+p.xc, yc+p.yc); }
  45.     Point operator-() const            { return Point(-xc,-yc); }
  46.     Point operator-(const Point& p) const    { return Point(xc-p.xc, yc-p.yc); }
  47.     friend Point operator*(const Point& p, int i) { return Point(i*p.xc, i*p.yc); }
  48.     friend Point operator*(int i, const Point& p) { return Point(i*p.xc, i*p.yc); }
  49.     int operator*(const Point& p) const    { return xc*p.xc + yc*p.yc; }
  50.     bool operator==(const Point& p) const    { return (xc==p.xc && yc==p.yc); }
  51.     bool operator!=(const Point& p) const    { return (xc!=p.xc || yc!=p.yc); }
  52.     bool operator<(const Point& p) const    { return (yc<p.yc && xc<p.xc); }
  53.     bool operator<=(const Point& p) const    { return (yc<=p.yc && xc<=p.xc); }
  54.     bool operator>(const Point& p) const    { return (yc>p.yc && xc>p.xc); }
  55.     bool operator>=(const Point& p) const    { return (yc>=p.yc && xc>=p.xc); }
  56.     void operator+=(const Point& p)        { xc += p.xc; yc += p.yc; }
  57.     void operator-=(const Point& p)        { xc -= p.xc; yc -= p.yc; }
  58.     void operator*=(int s)            { xc *= s; yc *= s; }
  59.     double dist(const Point& p) const    { return hypot(xc-p.xc, yc-p.yc); }
  60.     Point max(const Point&) const;
  61.     Point min(const Point&) const;
  62.     Point transpose() const            { return Point(yc,xc); }
  63.      bool isBelow(const Point& p) const    { return yc > p.yc; }
  64.     bool isAbove(const Point& p) const    { return yc < p.yc; }
  65.     bool isLeft(const Point& p) const    { return xc < p.xc; }
  66.     bool isRight(const Point& p) const    { return xc > p.xc; }
  67.     virtual    int compare(const Object&) const;    // compare Points 
  68.     virtual void deepenShallowCopy();    // {}
  69.     virtual unsigned hash() const;
  70.     virtual bool isEqual(const Object&) const;    // equality test 
  71.     virtual void printOn(ostream& strm =cout) const;
  72.     virtual const Class* species() const;
  73. };
  74.  
  75. #endif
  76.